<?php 
namespace app\index\controller;

use think\Controller;
use app\model\Commodity;
use app\model\Category;
use app\model\Picture;
use app\model\Order;
use think\Session;

class Commoditydo extends Controller{

// --------------卖家------------
	// 用户发布商品
	public function addCommodity(){

	}

	// 用户查询已审核商品
	public function getAuditedCommodityList(){

	}

	// 用户查询未审核商品列表
	public function getUnauditedCommodityList(){

	}

	// 用户查询已上架商品
	public function getSoleCommodityList(){

	}

	// 用户查询未上架商品列表
	public function getUnsoleCommodityList(){

	}

	// 用户上架商品
	public function soleCommodity(){

	}

	// 用户撤销商品
	public function removeCommodity(){

	}

	// 用户查看已售出商品
	public function SoledadCommodity(){

	}

	// 用户查看已撤销商品
	public function removedCommodity(){

	}

	// 用户修改商品信息，考虑图片的增删
	public function editCommodity(){

	}

	// 查询商品信息
	public function getCommodityInfo(){
		$commodity = Commodity::getInfo(input("commodity_id"));
		return getResponse(0,$commodity);
	}

	// 查找商品图片
	public function getCommodityPic(){
		$pictures = Picture::all(['commodity_id'=>input("commodity_id")]);

		return getResponse(0,$pictures);
	}

// --------------买家------------
	// 获取商品列表,考虑分页
	public function getCommodityList(){

	}

	// 查找商品
	public function findCommodity(){
		
	}

	// 用户购买商品
	public function addOrder(){
		if(!session::has("user_id")){
			return getResponse(1,"未登录");
		}
		$pars["order_id"] = getId();
		$pars["commodity_id"] = input("commodity_id");
		$pars["commodity_num"] = input("order_num");
		$pars["order_price"] = input("order_price");
		if(session::get("user_balance") < $pars["order_price"]){
			return getResponse(2,"余额不足");
		}
		$pars["user_id"] = Session::get("user_id");
		Order::create($pars);
		$commodity = Commodity::get(input("commodity_id"));
		$commodity->commodity_num-=input("order_num");
		$commodity->save();
		return getResponse(0,"成功");
	}

	// 用户退货
	public function backCommodity(){

	}

	// 用户查询已购商品列表
	public function getBuyCommodity(){
		$categorys = Category::getListByPage(10);
		$this->assign("categorys",$categorys);
		$orders = Order::getBuyCommodityByUser(Session::get("user_id"));
		$this->assign("orders",$orders);
		return $this->fetch();
	}

	// 用户查询已购商品信息
	public function getBuyCommodityInfo(){
		$order = Order::getInfo(input("order_id"));
		return getResponse(0,$order);
	}
}

 ?>